package com.project.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lyl
 * description:基本web配置类
 */
@Component
public class WebConfig implements WebMvcConfigurer {

    /**
     * mybatis-plus拦截器配置
     *
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    /**
     * 处理跨域问题
     *
     * @param registry
     */
    @SuppressWarnings("AlibabaAvoidCommentBehindStatement")
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  //跨域的URL
                .allowedHeaders("*")  //请求头
                .allowedMethods("*")  //请求方法
                .allowedOrigins("*");  //请求域名
    }

}